package com.example.shopping.controller;

import com.example.shopping.pojo.SpecificationOption;
import com.example.shopping.service.SpecificationOptionSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UnknownFormatConversionException;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/
@CrossOrigin
@Controller
public class SpecificationOptionController {
    @Autowired(required = false)
    public SpecificationOptionSerivce specificationOptionSerivce;

    //全部查询
    @RequestMapping("/SelectListSpecificationOption")
    public String SelectListSpecificationOption(HttpServletRequest request) {
        List<SpecificationOption> specificationOptions = specificationOptionSerivce.SelectListSpecificationOption();
        return "specificationOption";
    }

    //添加
    @RequestMapping("/insertSpecificationOption")
    public String insertSpecificationOption(SpecificationOption specificationOption) {
        int i = specificationOptionSerivce.insertSpecificationOption(specificationOption);
        if (i > 0) {
            return "redirect:SelectListSpecificationOption";
        }
        return "redirect:insertSpecificationOption";
    }

    //删除
    @RequestMapping("/deleteSpecificationById")
    public String deleteSpecificationById(HttpServletRequest request, int id) {
        int i = specificationOptionSerivce.deleteSpecificationById(id);
        if (i > 0) {
            return "redirect:SelectListSpecificationOption";
        }
        return "redirect:insertSpecificationOption";
    }

    //根据ID查询
    @RequestMapping("/selectListSpecificationOptionByCopyId")
    public String selectListSpecificationOptionByCopyId(HttpServletRequest request, int id) {
        SpecificationOption specificationOptions = specificationOptionSerivce.selectListSpecificationOptionByCopyId(id);
        request.getSession().setAttribute("specificationOptions", specificationOptions);
        return "updateSpecificationOption";
    }


}
